/*
 * Vent_graVerFact.java
 *
 * Created on 20 de agosto de 2006, 13:03
 */

package administrador;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.text.SimpleDateFormat;
import javax.swing.ImageIcon;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
/**
 *
 * @author  CARLOS SILVA
 */
public class Vent_graVerFact extends javax.swing.JFrame {
    
    /** Creates new form Vent_graVerFact */
    public Vent_graVerFact() {
        initComponents();
        setSize(724,500);
        setVisible(true);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        lblcha1 = new javax.swing.JLabel();

        getContentPane().setLayout(null);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jLabel1.setFont(new java.awt.Font("Stencil", 1, 36));
        jLabel1.setForeground(new java.awt.Color(0, 102, 102));
        jLabel1.setText("Graficas");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(20, 20, 240, 40);

        jLabel14.setForeground(new java.awt.Color(255, 153, 0));
        jLabel14.setText("Ventas");
        getContentPane().add(jLabel14);
        jLabel14.setBounds(180, 40, 70, 40);

        getContentPane().add(lblcha1);
        lblcha1.setBounds(20, 80, 680, 380);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    /**
     * @param args the command line arguments
     */
     public void creaGrafProgres(String titulo,String ejex,String ejey,Color fondo_Color,Color titulo_Color,Color tapiz,javax.swing.JLabel lbl_etiqueta,TimeSeries pop){
   //Crea un Grafico3D de Barras:
        //Especifica los datos a crear en un dataset.
        // Create a time series chart 
        TimeSeriesCollection dataset = new TimeSeriesCollection(); 
        dataset.addSeries(pop);
              
        
        JFreeChart chart = ChartFactory.createTimeSeriesChart(
            titulo,             //Title
            ejey,               //etiqueta eje x
            ejex,               //etiqueta eje y
            dataset,            //Dataset
            false,              //Muestra Leyenda
            true,               //Usa tooltips
            false               //Configura el chart para generar URLS?
        );
             
        


        //Le guarda  a la grafica como una imagen JPG:
//        try {
//            ChartUtilities.saveChartAsJPEG(new File("C:\\chart.jpg"), chart, 610, 150);
//        } catch (Exception e) {
//            System.out.println("Problem occurred creating chart.");
//        }
        //Cambio presentacion de los ejes de fechas:
        XYPlot plot = chart.getXYPlot();
        DateAxis axis = (DateAxis) plot.getDomainAxis();
        axis.setDateFormatOverride(new SimpleDateFormat("MMM-d"));
        
        
        //Personaliso:
       chart.setBackgroundPaint(tapiz); // Color Fondo 
       chart.getTitle().setPaint(titulo_Color); // Color Titulo Color.blue
       //CategoryPlot pc = chart.getCategoryPlot(); // Toma el objeto plot para un grafico de barra
//       pc.setBackgroundPaint(fondo_Color); // Modifica el Fondo del PlotColor.black
       //pc.setRangeGridlinePaint(Color.red); //Modifica el Color lineas Grilla
       
       //Carga la imagen Generada en un Label:
       
       
           //Creo un bufer de imagenes y le pongo en una etiqueta
           BufferedImage image = chart.createBufferedImage(680,380);
           lbl_etiqueta.setIcon(new ImageIcon(image));
           setVisible(true);
      
       
   }
    

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel14;
    public javax.swing.JLabel lblcha1;
    // End of variables declaration//GEN-END:variables
    
}
